package com.chenbei.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenbei.erp.domain.SupplierInvoice;
import com.chenbei.erp.mapper.SupplierInvoiceMapper;
import com.chenbei.erp.service.ISupplierInvoiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SupplierInvoiceService extends ServiceImpl<SupplierInvoiceMapper, SupplierInvoice> implements ISupplierInvoiceService {

    @Override
    public void addOrUpdate(SupplierInvoice supplierInvoice) {
        if (supplierInvoice.getId() != null) {
            updateById(supplierInvoice);
        } else {
            save(supplierInvoice);
        }
    }

    @Override
    public SupplierInvoice getBySupplierId(Long supplierId) {
        LambdaQueryWrapper<SupplierInvoice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SupplierInvoice::getSupplierId, supplierId).last("LIMIT 1");
        return getOne(lambdaQueryWrapper);
    }
}
